package com.aceitunaproject.gameclient;

import java.awt.Image;

import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.aceitunaproject.mapdisplay.resources.ImageLibrary;
import com.aceitunaproject.shared.gamelement.Installation;
import com.aceitunaproject.shared.gamelement.Settlement;
import com.aceitunaproject.shared.gamelement.Unit;

public class ElementDetails extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ElementDetails()
	{
		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	}
	
	public void setUnit(Unit unit) {

		this.removeAll();
		addLabel("Unit :");
		addLabel(Utility.getUnitImageName(unit),unit.getName());
		addLabel("Time Units :" + unit.getTimeUnits());
		addLabel("Player :" + unit.getPlayer().getName());
		addLabel("Persons:" + unit.getPersons());
		this.revalidate();
		this.repaint();
		
	}

	public void setInstallation(Installation installation) {
		this.removeAll();
		addLabel("Installation :");
		addLabel(Utility.getInstallationImageName(installation),installation.getName());
		addLabel("Type :" + installation.getType());
		addLabel("Player :" + installation.getPlayer().getName());
		this.revalidate();
		this.repaint();
	}

	public void setSettlement(Settlement settlement) {
		this.removeAll();
		addLabel("Settlement :");
		addLabel(Utility.getSettlementImageName(settlement),settlement.getName());
		addLabel("Population :" + settlement.getPersons());
		addLabel("Player :" + settlement.getPlayer().getName());
		this.revalidate();
		this.repaint();
	}

	
	private void addLabel(String text)
	{
		this.add(new JLabel(text));
	}
			
	private void addLabel(String imageName, String text) {
	
		
		this.add(new JLabel(text, getIcon(imageName), JLabel.RIGHT));
	}
	private Icon getIcon(String imageName)
	{
		Image image = ImageLibrary.getImage(imageName);

		Icon icon = new ImageIcon(image.getScaledInstance(32, 32,
				Image.SCALE_DEFAULT));
		return icon;

	}
}
